<template>
    <div class="divCommomStyle">
      <div class="content">
        <div class="title">
          <span>2019年4月统计数</span>
        </div>
        <div class="chartBox">
          <div class="left">
            <div id="radarChart" :style="{width: '100%', height: '100%'}"></div>
          </div>
          <div class="right">
            <div class="textBox" v-for="(item,index) in rightData" :key="index">
              <span>{{item.name}}</span>
              <span>{{item.value}}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
</template>

<script>
export default {
  data () {
    return {
      radarChart: null,
      rightData: [
        {name: '20天', value: '50'},
        {name: '20天', value: '50'},
        {name: '20天', value: '50'},
        {name: '20天', value: '50'},
        {name: '20天', value: '50'},
        {name: '20天', value: '50'}
      ],
      chartRadius: 70,
      clientHeight: '',
      clientWidth: ''
    }
  },
  mounted () {
    // 获取浏览器可视区域高度
    this.clientHeight = `${document.documentElement.clientHeight}`
    this.clientWidth = `${document.documentElement.clientWidth}`
    window.onresize = function temp () {
      this.clientHeight = `${document.documentElement.clientHeight}`
    }
    if (this.clientHeight <= 768 || this.clientWidth <= 1366) {
      this.chartRadius = 36
    }
    this.initRadarChart()
  },
  activated () {
    // 由于给echart添加了resize事件, 在组件激活时需要重新resize绘画一次, 否则出现空白bug
    if (this.radarChart) {
      this.radarChart.resize()
    }
  },
  methods: {
    initRadarChart () {
      console.log(this.chartRadius)
      let option = {
        backgroundColor: 'transparent',
        color: ['#0d2e4d'],
        grid: {
          width: '50%',
          height: '50%'
        },
        radar: {
          shape: 'circle',
          center: ['50%', '53%'],
          // radius: 36,
          radius: this.chartRadius,
          startAngle: 90,
          splitNumber: 3,
          name: {
            textStyle: {
              fontSize: '12',
              color: '#28acf0'
            }
          },
          axisLine: {
            show: false
          },
          splitLine: {
            lineStyle: {
              color: 'rgba(15, 47, 80, 1)'
            }
          },
          splitArea: {
            areaStyle: {
              color: 'transparent',
              shadowColor: 'rgba(0, 0, 0, 0.3)'
            }
          },
          indicator: [
            {
              name: '项目概况',
              max: 10
            },
            {
              name: '关注指数',
              max: 10
            },
            {
              name: '播放平台',
              max: 10
            },
            {
              name: '声量基础',
              max: 10
            },
            {
              name: '制作公司',
              max: 10
            },
            {
              name: '主创团队',
              max: 10
            }
          ]
        },
        series: [{
          type: 'radar',
          data: [{
            value: [7.5, 6.8, 4.5, 6, 4, 5.2],
            name: '数据',
            itemStyle: {
              normal: {
                color: 'rgba(40, 206, 87, 0.8)'
              }
            },
            areaStyle: {
              normal: {
                color: 'rgba(40, 206, 87, 0.3)'
              }
            }
          }]
        }]
      }
      this.radarChart = this.$echarts.init(document.getElementById('radarChart'))
      this.radarChart.setOption(option)
      window.addEventListener('resize', () => {
        this.radarChart.resize()
      })
    }
  }
}
</script>

<style scoped>
.divCommomStyle{
  display: flex;
  justify-content: center;
  align-items: center;
}
.divCommomStyle .content{
  display: flex;
  flex-flow: column;
}
.divCommomStyle .title{
  height: 30px;
  text-align: left;
  font-size: 14px;
  color: #29adf1;
}
.divCommomStyle .chartBox{
  display: flex;
  width: 100%;
  height: calc(100% - 35px);
  overflow: hidden;
}
.left{
  flex: 9;
  height: 100%;
}
.right{
  flex: 6;
  height: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  align-items: center;
}
.right .textBox{
  display: flex;
  width: 40%;
  height: 23%;
  padding:5px 0;
  background: #0a2043;
  border:1px solid #053b6a;
  justify-content: center;
  flex-flow: column;
  align-items: center;
}
.right .textBox span{
  display: block;
  color: #27a3e4;
  font-size: 2vh;
  line-height: 20px;
}
</style>
